﻿Public Class frmNhaCungcap

    Private Sub dgvDanhSachNCC_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachNCC.SelectionChanged
        HienThi()
    End Sub
    Public Sub LoadDanhSachLenLuoi()
        dgvDanhSachNCC.DataSource = NhaCungCapDAO.selectALL()
    End Sub
    Public Sub HienThi()
        If dgvDanhSachNCC.SelectedRows.Count > 0 Then
            txtMaNhaCungCap.Text = dgvDanhSachNCC.SelectedRows(0).Cells(0).Value.ToString()
            txtTenNhaCungCap.Text = dgvDanhSachNCC.SelectedRows(0).Cells(1).Value.ToString()
        End If
    End Sub

    Private Sub frmNhaCungcap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDanhSachLenLuoi()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim dvt As New NhaCungCapDTO
        dvt.MaNhaCungCap = txtMaNhaCungCap.Text
        dvt.TenNhaCungCap = txtTenNhaCungCap.Text
        NhaCungCapDAO.insert(dvt)
        LoadDanhSachLenLuoi()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim dvt As String
        dvt = txtMaNhaCungCap.Text
        NhaCungCapDAO.delete(dvt)
        LoadDanhSachLenLuoi()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Dim dvt As NhaCungCapDTO = New NhaCungCapDTO
        dvt.MaNhaCungCap = txtMaNhaCungCap.Text
        dvt.TenNhaCungCap = txtTenNhaCungCap.Text

        NhaCungCapDAO.Update(dvt)
        LoadDanhSachLenLuoi()
    End Sub
    Public Shared Function TimKiemNhaCungCapTen(ByVal Tenkh As String) As DataTable
        Dim strsql As String
        strsql = "SELECT * FROM NHACUNGCAP WHERE TENNHACUNGCAP LIKE '" & Tenkh & "%'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strsql)
        Return dt
    End Function
    Public Shared Function TimKiemNhaCungCapMa(ByVal MaKh As String) As DataTable
        Dim strsql As String
        strsql = "SELECT * FROM NHACUNGCAP WHERE MANHACUNGCAP = '" & MaKh & "'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strsql)
        Return dt
    End Function
End Class